package bearworker.zxl.utils;

import org.apache.log4j.Logger;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
import java.util.Map;

/**
 * Created by 逍遥的熊 on 2017/11/27.
 */

public class UrlUtil{

    private Logger logger = Logger.getLogger(UrlUtil.class);

    public UrlUtil(){

    }

    public void execute(String className,String methodName,Map<String,String> param,HttpUtil httpUtil){
        try {
            Object obj = SpringContext.getBean(className);
            Method method = ReflectionUtils.findMethod(obj.getClass(),methodName,new Class[]{Map.class});
            Object res = ReflectionUtils.invokeMethod(method,obj,param);
            logger.debug("方法返回值："+res);

            httpUtil.httpRes(200,res);
        }catch (Exception e){
            logger.error("类加载错误",e);
            httpUtil.httpRes(500,"类加载错误");
        }
    }
}
